package com.example.spark.service.minio;


import liquibase.repackaged.org.apache.commons.lang3.StringUtils;
import org.apache.tools.ant.util.DateUtils;

import java.io.InputStream;
import java.util.Date;
import java.util.UUID;

public abstract class AbstractCloudStorageService {
    /**
     * 定义文件路径
     *
     * @param prefix 前缀
     * @param suffix 后缀
     * @return 返回上传路径
     */
    public String getPath(String prefix, String suffix,String name) {
        //生成uuid
        String uuid = UUID.randomUUID().toString().replaceAll("-", "");
        String path = DateUtils.format(new Date(), "yyyyMMdd") + "/" + name;
        if (StringUtils.isNotBlank(prefix)) {
            path = prefix + "/" + path ;
        }
        return path + "." + suffix;
    }

    /**
     * 文件上传
     * @param data    文件字节数组
     * @param path    文件路径，包含文件名
     * @return        返回http地址
     */
    public abstract String uploadPhoto(byte[] data, String path);
    public abstract String uploadFile(byte[] data, String path,String currentType);
    public abstract String uploadVideo(byte[] data, String path);

    /**
     * 文件上传
     * @param data     文件字节数组
     * @param suffix   后缀
     * @return         返回http地址
     */
    public abstract String uploadPhotoSuffix(byte[] data, String suffix,String name);
    public abstract String uploadFileSuffix(byte[] data, String suffix,String name,String currentType);
    public abstract String uploadVideoSuffix(byte[] data, String suffix,String name);

    /**
     * 文件上传
     * @param inputStream   字节流
     * @param path          文件路径，包含文件名
     * @return              返回http地址
     */
    public abstract String uploadPhoto(InputStream inputStream, String path);
    public abstract String uploadFile(InputStream inputStream, String path,String currentType);
    public abstract String uploadVideo(InputStream inputStream, String path);

    /**
     * 文件上传
     * @param inputStream  字节流
     * @param suffix       后缀
     * @return             返回http地址
     */
    public abstract String uploadPhotoSuffix(InputStream inputStream, String suffix,String name);
    public abstract String uploadFileSuffix(InputStream inputStream, String suffix,String name,String currentType);
    public abstract String uploadVideoSuffix(InputStream inputStream, String suffix,String name);
}
